package Homework06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeMap;

public class Dapai {
	public static void main(String[] args) {

		ArrayList<Integer> poker = new ArrayList<>();
		TreeMap<Integer, String> hashMap = new TreeMap<Integer, String>();
		String[] colors = { "♠", "♥", "♦", "♣" };
		String[] numbers = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };

		hashMap.put(0, "JOKER");
		hashMap.put(1, "joker");

		int k = 2;
		for (String number : numbers) {
			for (String color : colors) {
				hashMap.put(k, color + number);
				k++;
			}
		}

		poker.addAll(hashMap.keySet());
		
		System.out.println(poker);
		System.out.println(hashMap);

		Collections.shuffle(poker);

		System.out.println(poker);

		Player p1 = new Player("张三");
		Player p2 = new Player("李四");
		Player p3 = new Player("王五");
		ArrayList<Integer> dipai = new ArrayList<>();

		for(int i = 0; i < poker.size(); i++) {
			int p = poker.get(i);
			Player player = i >= 51 ? null : (i % 3 == 0 ? p1 : (i%3 == 1?p2:p3));
			if(player != null){
				player.getPoker().add(p);
			}else{
				dipai.add(p);
			}
		}
		
		p1.getPoker().sort(Integer::compareTo);
        p2.getPoker().sort(Integer::compareTo);
        p3.getPoker().sort(Integer::compareTo);
        dipai.sort(Integer::compareTo);

        
        printPlayerCards(p1, hashMap);
        printPlayerCards(p2, hashMap);
        printPlayerCards(p3, hashMap);

        
        System.out.println("底牌：");
        dipai.stream()
                .map(hashMap::get)
                .forEach(card -> System.out.print(card + " "));
        System.out.println();

	}
	
	private static void printPlayerCards(Player player, TreeMap<Integer, String> hashMap) {
        System.out.println(player.getName() + "的牌：");
        player.getPoker().stream()
                .map(hashMap::get)
                .forEach(card -> System.out.print(card + " "));
        System.out.println();
    }

}
